<template>
  <div>
    <el-dialog :title="title" :visible.sync="dialogVisible" lock-scroll width="800px" center>
      <div class="dialog_div_new">
        <el-form :model="newData" :rules="rules" ref="ruleForm" class="demo-ruleForm">
          <el-row :gutter="24" style>
            <el-col :span="12">
              <el-form-item label="公司名称" prop="expressName">
                <el-input v-model="newData.expressName" @blur="getNameToPinying"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="拼音编码" prop="pinyinCode">
                <el-input v-model="newData.pinyinCode"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="公司简称" prop="expressAbbreviation">
                <el-input v-model="newData.expressAbbreviation"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="地址" prop="expressAddress">
                <el-input v-model="newData.expressAddress"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="联系人" prop="userName">
                <el-input v-model="newData.userName"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="联系电话" prop="expressLandline">
                <el-input v-model="newData.expressLandline"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="手机" prop="expressPhone">
                <el-input v-model="newData.expressPhone"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="传真" prop="expressFax">
                <el-input v-model="newData.expressFax"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="开户银行" prop="bankName">
                <el-input v-model="newData.bankName"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="账号" prop="bankNumber">
                <el-input v-model="newData.bankNumber"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="期初应收款" prop="startCollectPrice">
                <el-input v-model="newData.startCollectPrice"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="期初应付款" prop="startPayPrice">
                <el-input v-model="newData.startPayPrice"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="累计应收款" prop="allCollectPrice">
                <el-input v-model="newData.allCollectPrice"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="累计应付款" prop="allPayPrice">
                <el-input v-model="newData.allPayPrice"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="24">
              <el-form-item label="备注">
                <el-input type="textarea" v-model="newData.remark" :autoSize="{ minRows: 5 }"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="24">
              <el-form-item class="bottom_item">
                <el-button type="primary" @click.stop="onAddSubmit">保存</el-button>
                <el-button @click.stop="closeCancel">取消</el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props: {
    title: {
      type: String,
      default: '新增快递物流'
    },
  },
  data() {
    return {
      dialogVisible: false,
      rules: {
        expressName: [{ required: true, message: '请输入公司名称', trigger: 'blur' }],
        expressPhone: [
          { pattern: /^1[3|4|5|6|7|8|9]\d{9}$/, message: '请输入正确的手机号!' },
        ]
      },
      newData: {
        expressName: '',
          pinyinCode: '',
          expressAbbreviation: '',
          expressAddress: '',
          userName: '',
          expressLandline: '',
          expressPhone: '',
          expressFax: '',
          bankName: '',
          bankNumber: '',
          startCollectPrice: '',
          startPayPrice: '',
          allCollectPrice: '',
          allPayPrice: '',
          remark: '',
          expressNumber: ''//物流编码
      },
    }
  },
  methods: {
    add() {
      this.newData = this.$options.data().newData
      this.dialogVisible = true
    },
    edit(data) {
      this.newData = JSON.parse(JSON.stringify(data))
      this.dialogVisible = true
    },
    // 转换拼音码
    getNameToPinying(event) {
      this.newData.pinyinCode = this.$pinyin.getJp(event.target.value)
    },
    onAddSubmit() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          this.dialogVisible = !this.dialogVisible
          this.$emit('onAddSubmit', this.newData)
        }
      })

    },
    closeCancel() {
      // this.$emit('closeCancel', this.newData)
      this.dialogVisible = false
    },
  },
}
</script>

<style lang="scss" scoped>
.dialog_div_new {
  padding-top: -15px;
  width: 100%;
  // height: 60vh;
  // overflow: auto;
  background: #fff;
}

::v-deep .el-dialog__header {
  border-bottom: 1px solid #eee;
  padding: 20px 30px 15px;
}

::v-deep .el-dialog__body {
  padding: 15px 20px 20px;
  margin: 0 15px;
}

::v-deep .el-input__inner {
  height: 30px;
  line-height: 30px;
}

::v-deep .el-form-item__error {
  top: 34px !important;
}

::v-deep .el-form-item {
  display: flex;
  width: 100%;
  margin: 6px 0;

  .el-form-item__label {
    width: auto;
    min-width: 80px;
    line-height: 40px;
    font-size: 13px;
    font-family: PingFang SC;
    font-weight: 400;
    color: #666;
    text-align: justify;
    text-justify: distribute-all-lines;
    /*ie6-8*/
    text-align-last: justify;
    /* ie9*/
    -moz-text-align-last: justify;
    /*ff*/
    -webkit-text-align-last: justify;
    /*chrome 20+*/
    position: relative;

    &::before {
      position: absolute;
      right: 0;
      margin-right: 0;
      color: #ff0000;
      font-weight: 600;
    }
  }

  .el-form-item__content {
    flex: 1;
  }
}

.bottom_item {
  margin-top: 15px;
  width: 100%;
  box-sizing: border-box;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;

  ::v-deep .el-form-item__content {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  ::v-deep .el-button {
    width: 60px;
    height: 30px;
    text-align: center;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    border-radius: 5px;
    background: #fff;
    border: 1px solid #dddddd;
    color: #666666;
  }

  ::v-deep .el-button--primary {
    background: #1890ff;
    border-color: #1890ff;
    color: #fff;
    margin-right: 15px;
  }

  ::v-deep .el-button--default {
    margin-left: 0;
  }
}
</style>